import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Queue;

/**
 * 2530. 执行 K 次操作后的最大分数
 */
public class No2530 {
    public long maxKelements(int[] nums, int k) {
        Queue<Integer> heap = new PriorityQueue<>(Comparator.reverseOrder());
        for (int num : nums) {
            heap.offer(num);
        }
        long ans = 0;
        for (int i = 0; i < k; i++) {
            Integer poll = heap.poll();
            ans += poll;
            heap.offer((int) Math.ceil((double) poll / 3));
        }
        return ans;
    }
}
